<template>
	<div>
        <!--<a-header :goBack="goBack" :goAddAddress="goAddAddress"></a-header>-->
        <my-header :title="'收货地址'" :hasTitle="true" :hasBack="true" :goBack="goBack">
        	<slot name="zx">
        		<div id="add_address" style="padding-right: 0.8rem;width: 30%;text-align: right;position: relative;z-index: 5;" class="aui-pull-right text-del" @click.stop="goAddAddress">新增地址</div>
        	</slot>
        </my-header>
	</div>

</template>

<script>
import MyHeader from "../../header";
import Header from "../../../real-components/AddressHeader";
import {mapGetters,mapMutations} from "vuex";

export default {
  	name: 'hello',
  	data () {
    	return {
			msg: '这是收货地址页面',
            page: "AddressHeader",
            componentName: "AddressHeader",
            dataList: []
		}
	},
	computed: {
		...mapGetters('zx',[
			"getAddressList"
		])
	},
	components: {
        "a-header": Header,
        "my-header":MyHeader
    },
    methods: {
        ...mapMutations('zx',[
			'setaddFlagMutation',"setNowAddressMutation"
		]),
		goAddAddress(){
			let obj = {
				sex:"男",
				label:"家庭",
				defaultaddress:"非默认",
				phone:'',
				province:'',
				city:'',
				region:'',
				address:'',
				receivername:'',
				result:'',
				houseNumber:''
			}
			this.setaddFlagMutation(true);
			this.setNowAddressMutation(obj);
			//存local 防止vuex失效  当失效时取用
			localStorage.setItem('userAddressNow',JSON.stringify(obj));
			let id = this.$route.query.id;
			if(id){
				this.$router.push({path:'addAddress',query:{id:2}});
			}else{
				this.$router.push('addAddress');
			}
		},
		goBack(){
			let id = this.$route.query.id;
			if(id){
//				window.history.back();
				var obj = {};
				if(this.getAddressList &&  this.getAddressList.length){
					for(let i = 0; i < this.getAddressList.length; i++){
						if(this.getAddressList[i].isNew == 0){
							console.log(this.getAddressList[i],'返回订单地址')
							obj = this.getAddressList[i];
						}
					}
					obj.flag = true;
				}else{
					obj.flag = false;
				}
				this.$router.push({path:'confirmOrder',query:{name:obj}});
			}else{
				this.$router.push('profile');
			}
			
		}
    },
	created () {
		
	},
	mounted () {
		// initDomTree(this.getDomTree[this.page]);
		
	},
	updated() {
		//页面更新完毕
		// initDomTree(this.getDomTree[this.page]);
	}
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
	.box {
		/* display: flex; */
	}
	.style-components {
		display: flex;
		flex-flow: column nowrap;
	}
	.container {
		width: 800px;
		height: 300px;
		border: 1px solid red;

	}
	.detail{
		width: 50%;
	}
</style>
